package com.kgc.community.service.impl;

import com.kgc.community.mapper.SchedulingMapper;
import com.kgc.community.pojo.Scheduling;
import com.kgc.community.pojo.SchedulingExample;
import com.kgc.community.service.SchedulingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author cbh
 */
import java.util.List;

@Service
public class SchedulingServiceImpl implements SchedulingService {

    @Autowired
    SchedulingMapper schedulingMapper;

    @Override
    public Integer addSchedulingSelective(Scheduling scheduling) {
        int res = schedulingMapper.insertSelective(scheduling);

        return res;
    }

    @Override
    public Integer updateSchedulingSelective(Scheduling scheduling) {
        int res = schedulingMapper.updateByPrimaryKeySelective(scheduling);

        return res;
    }

    @Override
    public Integer deleteSchedulingById(Integer id) {
        int res = schedulingMapper.deleteByPrimaryKey(id);
        return res;
    }

    @Override
    public List<Scheduling> searchSchedulingByRole(Integer roleId) {
        SchedulingExample example = new SchedulingExample();
        example.createCriteria().andRoleIdEqualTo(roleId);
        example.setOrderByClause("week");
        example.setOrderByClause("start_time");

        List<Scheduling> schedulings = schedulingMapper.selectByExample(example);

        return schedulings;
    }
}
